import pymysql
import logging
import time
import random
import uuid



def time_str():
    a1=(2019,5,1,0,0,0,0,0,0)
    a2=(2019,5,30,23,59,59,0,0,0)

    start=time.mktime(a1)
    end=time.mktime(a2)

    t=random.randint(start,end)
    date_touple=time.localtime(t)
    date=time.strftime("%Y-%m-%d %H:%M:%S",date_touple)

    return date




def getUUID():
    return "".join(str(uuid.uuid4()).split("-")).upper()

def insert_mysql():
    conn = pymysql.connect(host="47.107.112.135", user='sc', password='sc', database='sc', port=3306, charset="utf8")

    cursor = conn.cursor()
    for i in range(2):
        instance_id = getUUID()
        tenant_id = getUUID()
        model_id= getUUID()
        mt_id = getUUID()
        model_instance_creator_id = getUUID()
        mds_id = getUUID()
        model_versions = 'VI'
        model_instance_name = "instance name" + str(random.randint(1000, 100000))
        model_instance_status = str(random.randint(0, 4))
        versions_publish_status = str(random.randint(0, 4))
        fail_count = str(random.randint(0, 2))
        modify_time = time_str()
        model_instance_starttime = time_str()
        model_instance_endtime = time_str()
        insert_sql = f"INSERT INFO calc_model_instance (id,modify_time,tenant_id,model_id,mt_id,model_version," + \
                          "model_instance_name,model_instance_creator_id,mds_id,model_instance_status,model_instance_starttime,model_instance_endtime,versions_publish_status,fail_count)" + \
                          f'VALUES("{instance_id}","{modify_time}","{tenant_id}","{model_id}","{mt_id}",' + \
                          f'"{model_versions}","{model_instance_name}",' + \
                          f'''"{model_instance_creator_id}","{mds_id}","{model_instance_status}",'{model_instance_starttime}',"{model_instance_endtime}","{versions_publish_status}","{fail_count}")'''

        cursor.execute(insert_sql)

    cursor.close()
    conn.close()


if __name__ == "__main__":
    a1=(2019,5,1,0,0,0,0,0,0)
    a2=(2019,5,30,23,59,59,0,0,0)

    start=time.mktime(a1)
    end=time.mktime(a2)

    t=random.randint(start, end)
    date_touple=time.localtime(t)
    date=time.strftime("%Y-%m-%d %H:%M:%S",date_touple)
    print(date)
    #insert mysql()